package com.xauto.pioneer.appuser.model;

import android.content.Context;
import android.util.Log;

import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Table;

import org.json.JSONObject;

/**
 * 地区对象
 * Created by Lemon on 19/04/2017.
 */
@Table(name = "table_client_setting")
public class ClientSetting extends BaseModel<ClientSetting> {

    /**
     * 联系电话
     */
    @Id(column = "contact_number")
    public String contact_number;
    /**
     * 官方网站
     */
    public String contact_website;
    /**
     * email
     */
    public String contact_email;
    /**
     * 加油开票公司名称
     */
    public String refuel_company_name;

    public String getContact_number() {
        return contact_number;
    }

    public void setContact_number(String contact_number) {
        this.contact_number = contact_number;
    }

    public String getContact_website() {
        return contact_website;
    }

    public void setContact_website(String contact_website) {
        this.contact_website = contact_website;
    }

    public String getContact_email() {
        return contact_email;
    }

    public void setContact_email(String contact_email) {
        this.contact_email = contact_email;
    }

    public String getRefuel_company_name() {
        return refuel_company_name;
    }

    public void setRefuel_company_name(String refuel_company_name) {
        this.refuel_company_name = refuel_company_name;
    }

    @Override
    public ClientSetting parse(JSONObject jsonObject) {
        if (jsonObject != null) {
            contact_number = jsonObject.optString("contact_number");
            contact_website = jsonObject.optString("contact_website");
            contact_email = jsonObject.optString("contact_email");
            refuel_company_name = jsonObject.optString("refuel_company_name");
            return this;
        }
        return null;
    }

    @Override
    public boolean equals(Object o) {
        if (((ClientSetting) o).contact_number.equals(contact_number)) {
            return true;
        }
        return false;
    }

    public void saveDb(Context mContext, ClientSetting clientSetting) {
        FinalDb finalDb = FinalDb.create(mContext);
//        finalDb.delete(ClientSetting.class);
        finalDb.deleteByWhere(ClientSetting.class, "contact_number = \"" + clientSetting.contact_number + "\"");
        Log.e("saveDb", clientSetting.refuel_company_name);
        finalDb.save(clientSetting);
    }
}
